package com.znsd.zl.dict.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znsd.zl.dict.dao.DictDao;
import com.znsd.zl.dict.entity.DictEntity;
import com.znsd.zl.dict.service.IDictService;
import com.znsd.zl.dict.utils.ConditionPageUtils;
import com.znsd.zl.dict.utils.RedisTemplateUtils;
import com.znsd.zl.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @ClassName DictDao
 * @Description TODO
 * @Author zhubin
 * @Date 2020/8/17 19:52
 * @Version v1.0
 */
@Slf4j
@Service
public class DictServiceImpl extends ServiceImpl<DictDao, DictEntity> implements IDictService {

    @Autowired
    RedisTemplateUtils redisTemplateUtils;

    /**
     *  通过map动态的进行条件查询
     * @param params 封装的查询条件
     * @return 返回封装的分页对象
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        return ConditionPageUtils.conditionPage(params, this.getBaseMapper());
    }

    @Override
    public boolean save(DictEntity entity) {
        try {
            System.out.println(entity);
            int row = this.baseMapper.insert(entity);
            return (row == 1);
        } catch (Exception e) {
            log.error("dictService save sqlException  You can't add it repeatedly");
        }
        return false;
    }

    @Override
    public boolean updateById(DictEntity entity) {
        try {
            int row = this.baseMapper.updateById(entity);
            return row == 1;
        } catch (Exception e) {
            log.error("dictService update sqlException  You can't add it repeatedly");
        }
        return false;
    }
}
